/*     */ package com.cr.generator.util;
/*     */ 
/*     */ import com.cr.common.constant.GenConstants;
/*     */ import com.cr.common.utils.MyStringUtils;
/*     */ import com.cr.generator.config.GenConfig;
/*     */ import com.cr.generator.domain.GenTable;
/*     */ import com.cr.generator.domain.GenTableColumn;
/*     */ import java.util.Arrays;
/*     */ import org.apache.commons.lang3.RegExUtils;
/*     */ 
/*     */ public class GenUtils {
/*     */   public static void initTable(GenTable genTable, String operName) {
/*  23 */     genTable.setClassName(convertClassName(genTable.getTableName()));
/*  24 */     genTable.setPackageName(GenConfig.getPackageName());
/*  25 */     genTable.setModuleName(getModuleName(GenConfig.getPackageName()));
/*  26 */     genTable.setBusinessName(getBusinessName(genTable.getTableName()));
/*  27 */     genTable.setFunctionName(replaceText(genTable.getTableComment()));
/*  28 */     genTable.setFunctionAuthor(GenConfig.getAuthor());
/*  29 */     genTable.setCreateBy(operName);
/*     */   }
/*     */   
/*     */   public static void initColumnField(GenTableColumn column, GenTable table) {
/*  37 */     String dataType = getDbType(column.getColumnType());
/*  38 */     String columnName = column.getColumnName();
/*  39 */     column.setTableId(table.getTableId());
/*  40 */     column.setCreateBy(table.getCreateBy());
/*  42 */     column.setJavaField(MyStringUtils.toCamelCase(columnName));
/*  44 */     column.setJavaType("String");
/*  46 */     if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) {
/*  49 */       Integer columnLength = getColumnLength(column.getColumnType());
/*  50 */       String htmlType = (columnLength.intValue() >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) ? "textarea" : "input";
/*  51 */       column.setHtmlType(htmlType);
/*  53 */     } else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
/*  55 */       column.setJavaType("Date");
/*  56 */       column.setHtmlType("datetime");
/*  58 */     } else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
/*  60 */       column.setHtmlType("input");
/*  63 */       String[] str = MyStringUtils.split(MyStringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
/*  64 */       if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
/*  66 */         column.setJavaType("BigDecimal");
/*  69 */       } else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
/*  71 */         column.setJavaType("Integer");
/*     */       } else {
/*  76 */         column.setJavaType("Long");
/*     */       } 
/*     */     } 
/*  81 */     column.setIsInsert("1");
/*  84 */     if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk())
/*  86 */       column.setIsEdit("1"); 
/*  89 */     if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk())
/*  91 */       column.setIsList("1"); 
/*  94 */     if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk())
/*  96 */       column.setIsQuery("1"); 
/* 100 */     if (MyStringUtils.endsWithIgnoreCase(columnName, "name"))
/* 102 */       column.setQueryType("LIKE"); 
/* 105 */     if (MyStringUtils.endsWithIgnoreCase(columnName, "status")) {
/* 107 */       column.setHtmlType("radio");
/* 110 */     } else if (MyStringUtils.endsWithIgnoreCase(columnName, "type") ||
/* 111 */       MyStringUtils.endsWithIgnoreCase(columnName, "sex")) {
/* 113 */       column.setHtmlType("select");
/* 116 */     } else if (MyStringUtils.endsWithIgnoreCase(columnName, "file")) {
/* 118 */       column.setHtmlType("upload");
/* 121 */     } else if (MyStringUtils.endsWithIgnoreCase(columnName, "content")) {
/* 123 */       column.setHtmlType("summernote");
/*     */     } 
/*     */   }
/*     */   
/*     */   public static boolean arraysContains(String[] arr, String targetValue) {
/* 136 */     return Arrays.<String>asList(arr).contains(targetValue);
/*     */   }
/*     */   
/*     */   public static String getModuleName(String packageName) {
/* 147 */     int lastIndex = packageName.lastIndexOf(".");
/* 148 */     int nameLength = packageName.length();
/* 149 */     String moduleName = MyStringUtils.substring(packageName, lastIndex + 1, nameLength);
/* 150 */     return moduleName;
/*     */   }
/*     */   
/*     */   public static String getBusinessName(String tableName) {
/* 161 */     int lastIndex = tableName.lastIndexOf("_");
/* 162 */     int nameLength = tableName.length();
/* 163 */     String businessName = MyStringUtils.substring(tableName, lastIndex + 1, nameLength);
/* 164 */     return businessName;
/*     */   }
/*     */   
/*     */   public static String convertClassName(String tableName) {
/* 175 */     boolean autoRemovePre = GenConfig.getAutoRemovePre();
/* 176 */     String tablePrefix = GenConfig.getTablePrefix();
/* 177 */     if (autoRemovePre && MyStringUtils.isNotEmpty(tablePrefix)) {
/* 179 */       String[] searchList = MyStringUtils.split(tablePrefix, ",");
/* 180 */       tableName = replaceFirst(tableName, searchList);
/*     */     } 
/* 182 */     return MyStringUtils.convertToCamelCase(tableName);
/*     */   }
/*     */   
/*     */   public static String replaceFirst(String replacementm, String[] searchList) {
/* 194 */     String text = replacementm;
/* 195 */     for (String searchString : searchList) {
/* 197 */       if (replacementm.startsWith(searchString)) {
/* 199 */         text = replacementm.replaceFirst(searchString, "");
/*     */         break;
/*     */       } 
/*     */     } 
/* 203 */     return text;
/*     */   }
/*     */   
/*     */   public static String replaceText(String text) {
/* 214 */     return RegExUtils.replaceAll(text, "(?:表|若依)", "");
/*     */   }
/*     */   
/*     */   public static String getDbType(String columnType) {
/* 225 */     if (MyStringUtils.indexOf(columnType, "(") > 0)
/* 227 */       return MyStringUtils.substringBefore(columnType, "(");
/* 231 */     return columnType;
/*     */   }
/*     */   
/*     */   public static Integer getColumnLength(String columnType) {
/* 243 */     if (MyStringUtils.indexOf(columnType, "(") > 0) {
/* 245 */       String length = MyStringUtils.substringBetween(columnType, "(", ")");
/* 246 */       return Integer.valueOf(length);
/*     */     } 
/* 250 */     return Integer.valueOf(0);
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-generator-4.7.0.jar!\com\cr\generato\\util\GenUtils.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */